package com.water.skin.utils

import android.content.Context
import com.water.skin.constant.SkinConfig

class PrefUtils(private val mContext: Context) {
    val pluginPath: String?
        get() {
            val sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE)
            return sp.getString(SkinConfig.KEY_PLUGIN_PATH, "")
        }
    val suffix: String?
        get() {
            val sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE)
            return sp.getString(SkinConfig.KEY_PLUGIN_SUFFIX, "")
        }

    fun clear(): Boolean {
        val sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE)
        return sp.edit().clear().commit()
    }

    fun putPluginPath(path: String?) {
        val sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE)
        sp.edit().putString(SkinConfig.KEY_PLUGIN_PATH, path).apply()
    }

    fun putPluginPkg(pkgName: String?) {
        val sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE)
        sp.edit().putString(SkinConfig.KEY_PLUGIN_PKG, pkgName).apply()
    }

    val pluginPkgName: String? =
        mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE)
            .getString(SkinConfig.KEY_PLUGIN_PKG, "")

    fun putPluginSuffix(suffix: String?) {
        val sp = mContext.getSharedPreferences(SkinConfig.PREF_NAME, Context.MODE_PRIVATE)
        sp.edit().putString(SkinConfig.KEY_PLUGIN_SUFFIX, suffix).apply()
    }
}